package cn.edu.ecut.synchronize;

public class Sun {
	
	private static Sun singleton ;
	
	private Sun() {
		super();
	}
	
	// 对于类方法来说，同步锁就是当前类对应的 Class对象
	public synchronized static Sun getInstance() {
		Thread.yield(); // 线程让位
		if( singleton == null ) {
			singleton = new Sun();
		}
		return singleton ;
	}
	
	/*
	public static Sun getInstance() {
		synchronized ( Sun.class ) { // 以Sun.class实例为同步锁
			Thread.yield();
			if( singleton == null ) {
				singleton = new Sun();
			}
		}
		return singleton ;
	}
	*/

}
